#!/usr/local/python3.7/bin python3

__author__ = '无崖子'

from log import logger
import requests
from sign import zk_md5_sign


class ChannelId26(object):
    """
    应借贷 web http://119.23.224.34:9209/thirdParty/hmwx/hit(测试地址）
              http://sxj.match.91zrx.com/thirdParty/hmwx/hit(正式地址）
    {
    "bizCode": "success",
    "msg": "成功",
    "bizData": {
    "hit": "true",
    "userInfoMD5": "4265E71967484486EF0244A2433C8884"
        }
    }
    """

    def __init__(self, id_card=None):
        self.headers = {
            'accept': '*/*',
            'Content-Type': 'application/json',
        }
        self.session = requests.session()
        self.session.headers.update(self.headers)
        self.id_card = id_card

    def check_account(self, mobile):
        try:
            url = 'http://119.23.224.34:9209/thirdParty/hmwx/hit'
            result = self.session.post(url, json=zk_md5_sign(mobile + self.id_card)).json()
            if result['bizCode'] == 'success':
                return {'code': '0', 'isRegister': True, 'mobile': mobile}
            else:
                return {'code': '1', 'isRegister': False, 'mobile': mobile}
        except Exception as e:
            logger.exception('优逸贷渠道撞库出错:应借贷,{}').format(e)
            return {'code': '1', 'isRegister': False, 'mobile': mobile}
